﻿using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Windows.Data;
using MouseExtender.Logic.Managers;

namespace MouseExtender.Logic.Converters
{
    public class CurrentCultureConverter : IValueConverter
    {
        #region IValueConverter Members

        public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            CultureInfo cultureInfo = value as CultureInfo;
            if (cultureInfo == null)
                return null;

            //to boolean
            if (targetType == typeof(bool))
            {
                bool notInverse = System.Convert.ToBoolean(parameter);
                bool isCurrent = ResourceManager.IsCurrentCulture(cultureInfo);
                isCurrent = notInverse ? isCurrent : !isCurrent;
                return isCurrent;
            }

            //to string
            if (targetType == typeof(object))
            {
                string nativeName = cultureInfo.NativeName;
                if (cultureInfo.Name == "uk-UA")
                {
                    nativeName = "українська (Україна)";
                }

                return nativeName;
            }

            return null;
        }

        public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
